package demo1;


import java.util.Objects;

class A{
    public int id;
    public A(int id){
        this.id = id;
    }

    public boolean equals(Object obj) {
        //根据你自己的规则，判断是不是一样的两个对象
        if (obj == null) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        //不是Person类对象
        if ( !(obj instanceof Person)) {
            return false;
        }
        A tmp = (A) obj;//向下转型，比较属性值
        return this.id == tmp.id;
    }

    /*@Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        A a = (A) o;
        return id == a.id;
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }*/

    //重写归重写，不能胡来，除非业务需求
    public boolean equalsError(Object obj) {
        return true;
    }
}

class B{

}

public class TestDemo4 {

    public static void main(String[] args) {
        Object[] array = {1,2,3,"hello",4,5,6.7};
        //Integer[] tmp = (Object[])array;
    }

    public static void main5(String[] args) {
        //Object接受数据对象，向上转型
        Object obj = new int[]{1,2,3,4,5,6,7};
        //向下转型，需要强转
        int[] data = (int[]) obj;
        for (int i : data){
            System.out.print(i + "、");
        }
    }

    public static void main4(String[] args) {
        A a1 = new A(1);
        String str = "123";
        System.out.println(a1.equals(str));
    }

    public static void main3(String[] args) {
        A a1 = new A(1);
        A a2 = a1;
        System.out.println(a1.equals(a2));
    }

    public static void main2(String[] args) {
        A a1 = new A(1);
        A a2 = new A(1);
        System.out.println(a1 == a2);
        System.out.println(a1.equals(a2));
    }

    public static void func(Object obj){

    }
    public static void main1(String[] args) {
        func(new A(1));
        func(new B());
    }
}
